/**
 * 从文件路径字符串提取文件名的示例程序
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>


int main()
{
    char *file_path = "/home/martin/workspace/test.txt";
    char *seperator_pos = strrchr(file_path, '/');
    char file_name[256];

    if (seperator_pos == NULL) {
        fprintf(stderr, "Not a valid file path: %s\n", file_path);
        exit(1);
    }

    char *p = seperator_pos + 1;
    int i = 0;
    while (*p != '\0') {
        file_name[i++] = *p;
        p++;
    }
    file_name[i] = '\0';

    printf("file name is %s\n", file_name);

    return 0;
}

